<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>
    <button>发送请求</button>

    <script type="text/javascript">
        const btn = document.querySelector("button");
        //标识变量，是否发送AJAX请求
        let isSending = false;
        let xhr =null;
        btn.onclick = function () {
            if(isSending){
                xhr.abort();
            }
            isSending = true;
            xhr = new XMLHttpRequest();
            xhr.open("get", "http://127.0.0.1:8000/delay");
            xhr.send();
            xhr.onreadystatechange = function(){
                if(xhr.readystate === 4){ 
                    isSending = false;
                }
            }
        }



    </script>
</body>

</html>